// pages/tool/business-card/business-card.js
const app = getApp();
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		dataList:null,
		myinfo:null,
		showShare:null,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onShow: function () {
		this.myinfos();
	},

	myinfos() {
		app.func.getPromise('/my/info')
			.then(([code, res]) => {
				this.setData({
					myinfo: res.message
				},()=>{
					this.cardList(res.message.type);
				});
			})
	},
	cardList(type){
		if(type == 1 || type == 3){
			app.func.getPromise('/westorecard/list')
				.then(([code,res])=>{
					if(code == 200){
						this.setData({dataList : res.data});
					}
				})
		}else{
			app.func.getPromise('/westorecard/favouriteList')
				.then(([code,res])=>{
					if(code == 200){
						this.setData({dataList : res.data});
					}
				})
		}

	},

	edit(e){
		let item = e.currentTarget.dataset.item;
		wx.navigateTo({
			url:'/tools/pages/tool/business-card/add-card/add-card?modify=1&item=' + JSON.stringify(item)
		})
	},


	cancelFavourite(e) {
		let id = e.currentTarget.dataset.id;
		app.func.getPromise(`/westorecard/cancelFavourite/${id}`)
			.then(([code, res]) => {
				if (code == 200) {
					app.func.toastPromise('删除成功')
						.then(()=>{
							this.myinfos();
						})
				} else {
					app.func.toastPromise(res.message);
				}
			})
	},


	cancelShare() {
		this.setData({showShare: false});
	},
	showShare(e) {
		let item = e.currentTarget.dataset.item;
		this.setData({
			shareInfo: item,
			shareTitle: item.name + '的名片,请查收！',
			showShare: true,
		});
	},
	getInputValue(e) {
		this.setData({
			shareTitle: e.detail.value
		});
	},
	/**
	 * 用户点击立即送出
	 */
	onShareAppMessage: function () {
		return {
			title: this.data.shareTitle,
			imageUrl: `https://files.dianlinet.com/dianli/images/2020-10-19/16-59-39.jpg`,
			path: `/tools/pages/tool/business-card/share/share?id=${this.data.shareInfo.id}`
		}
	},

	view_detail(e){
		let id = e.currentTarget.dataset.id;
	    wx.navigateTo({
			url:`/tools/pages/tool/business-card/share/share?id=${id}`
		})
	},


	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */


	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},
})
